package com.aidex.biz.controller;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.aidex.common.utils.uuid.UUID;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.LianzhengJianshe;
import com.aidex.biz.service.LianzhengJiansheService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 廉政建设Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/biz/bizLianzhengJianshe")
public class LianzhengJiansheController extends BaseController
{
    @Autowired
    private LianzhengJiansheService lianzhengJiansheService;

    /**
     * 查询廉政建设列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizLianzhengJianshe:list')")
    @GetMapping("/list")
    public R<PageInfo> list(LianzhengJianshe lianzhengJianshe, HttpServletRequest request, HttpServletResponse response)
    {
        if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                lianzhengJianshe.setCompanyId(null);
        }else{
                     lianzhengJianshe.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                 }
        lianzhengJianshe.setPage(new PageDomain(request, response));
        return R.data(lianzhengJiansheService.findPage(lianzhengJianshe));
    }

    /**
     * 获取廉政建设详细信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizLianzhengJianshe:query')")
    @GetMapping(value = "/{id}")
    public R<LianzhengJianshe> detail(@PathVariable("id") String id)
    {
        return R.data(lianzhengJiansheService.get(id));
    }

    /**
     * 新增廉政建设
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizLianzhengJianshe:add')")
    @Log(title = "廉政建设", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  LianzhengJianshe lianzhengJianshe)
    {
        lianzhengJianshe.setIsNewRecord();
        return R.status(lianzhengJiansheService.save(lianzhengJianshe));
    }

    /**
     * 修改廉政建设
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizLianzhengJianshe:edit')")
    @Log(title = "廉政建设", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated LianzhengJianshe lianzhengJianshe)
    {
        return R.status(lianzhengJiansheService.save(lianzhengJianshe));
    }


    /**
     * 删除廉政建设
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizLianzhengJianshe:remove')")
    @Log(title = "廉政建设", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(lianzhengJiansheService.deleteLianzhengJiansheByIds(ids));
    }

    /**
     * 获取最大编号
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizLianzhengJianshe:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(lianzhengJiansheService.findMaxSort(new LianzhengJianshe()));
    }

    /**
     * 导出廉政建设列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizLianzhengJianshe:export')")
    @Log(title = "廉政建设", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(LianzhengJianshe lianzhengJianshe)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    lianzhengJianshe.setCompanyId(null);
            }else{
                         lianzhengJianshe.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<LianzhengJianshe> list = lianzhengJiansheService.findList(lianzhengJianshe);
        ExcelUtil<LianzhengJianshe> util = new ExcelUtil<LianzhengJianshe>(LianzhengJianshe.class);
        return util.exportExcel(list, "廉政建设数据");
    }

    @GetMapping("/getUUID")
    public R getUUID(LianzhengJianshe lianzhengJianshe) {
        return R.data(UUID.fastUUID().toString());
    }

    }
